﻿using System.Collections.Generic;
using UnityEngine;

namespace JH
{
    /// <summary>
    ///  数据点按Vector2类型的值进行排序的处理器
    /// </summary>
    public class Vector2ComparerByX: IComparer<Vector2>,IEqualityComparer<Vector2>
    {
        /// <summary>
        ///  比较器
        /// </summary>
        public static readonly Vector2ComparerByX Comparer = new();
        
        /// <summary>
        ///  X值比较器，用于对数据点按X值进行排序
        /// </summary>
        public int Compare(Vector2 a, Vector2 b)
        {
            // 按X值进行比较
            return a.x.CompareTo(b.x);
        }

        public bool Equals(Vector2 a, Vector2 b)
        {
            // 只比较X值是否相等
            return a.x.Equals(b.x);
        }

        public int GetHashCode(Vector2 obj)
        {
            // 使用X值的哈希码作为对象的哈希码
            return obj.x.GetHashCode();
        }
    }
}